﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Sale_Operation;
using Sale_Common;
namespace SaleSystem.ComPage
{
    public partial class frm_BillList : PageBase
    {
        #region PageEvent
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.Id = ValueHandler.GetIntNumberValue( Request["Id"]);
                GetAndBind();
            }
            else if (Request[LinkService.RefreshTag] == LinkService.RefreshString)
            {
                GetAndBind();
            }
        }
        protected void gv_List_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            gv_List.PageIndex = e.NewPageIndex;
        }
        protected void gv_List_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
        {
            if (e.CommandName.ToLower() == "edit")
            {
                if (Request["Type"] == "1")
                {
                    win_Content2.Hidden = false;
                    win_Content2.IFrameUrl = "../Business/frm_SaleBillEdit.aspx?Id=" + ValueHandler.GetIntNumberValue(gv_List.DataKeys[e.RowIndex][0]);
                    win_Content2.Title = "编辑-" + ValueHandler.GetStringValue(gv_List.DataKeys[e.RowIndex][1]);
                }
                else if (Request["Type"] == "2")
                {
                    win_Content2.Hidden = false;
                    win_Content2.IFrameUrl = "../Business/frm_BuyEdit.aspx?Id=" + ValueHandler.GetIntNumberValue(gv_List.DataKeys[e.RowIndex][0]);
                    win_Content2.Title = "编辑-" + ValueHandler.GetStringValue(gv_List.DataKeys[e.RowIndex][1]);
                }
                else if (Request["Type"] == "3")
                {
                    win_Content2.Hidden = false;
                    win_Content2.IFrameUrl = "../Business/frm_SaleBillEdit.aspx?Id=" + ValueHandler.GetIntNumberValue(gv_List.DataKeys[e.RowIndex][0]);
                    win_Content2.Title = "编辑-" + ValueHandler.GetStringValue(gv_List.DataKeys[e.RowIndex][1]);
                }
            }
            else if (e.CommandName.ToLower() == "ok")
            {
                if (Request["Type"] == "3")
                {
                    //TreeNodeCollection nodes 
                    string strText = ValueHandler.GetStringValue(gv_List.DataKeys[e.RowIndex][1]);
                    string strValue = ValueHandler.GetStringValue(gv_List.DataKeys[e.RowIndex][0]);

                    ExtAspNet.PageContext.RegisterStartupScript(ExtAspNet.ActiveWindow.GetWriteBackValueReference(strText, strValue) + ExtAspNet.ActiveWindow.GetHidePostBackReference("GetSaleBillDetail"));
                }
            }
        }
        #endregion
        #region Method
        private void GetAndBind()
        {
            //获取销售单
            int iRecordCount=0;
            if (Request["Type"] == "1")
            {
                dtList = Manager.GetSallBillList("SBDeta_PInfo_Id="+this.Id, gv_List.PageIndex, ref iRecordCount);
                this.gv_List.Columns[2].HeaderText = "销售单号";
                this.gv_List.Columns[3].HeaderText = "客户名称";
                this.gv_List.Columns[4].HeaderText = "销售日期";
            }
            else if (Request["Type"] == "2")
            {
                dtList = Manager.GetBuyBillList("BBDeta_PInfo_Id=" + this.Id, gv_List.PageIndex, ref iRecordCount);
                this.gv_List.Columns[2].HeaderText = "进货单号";
                this.gv_List.Columns[3].HeaderText = "供应商";
                this.gv_List.Columns[4].HeaderText = "进货日期";

            }
            else if (Request["Type"] == "3")
            {
                dtList = Manager.GetSaleBill("", gv_List.PageIndex, ref iRecordCount);
                this.gv_List.Columns[2].HeaderText = "销售单号";
                this.gv_List.Columns[3].HeaderText = "客户名称";
                this.gv_List.Columns[4].HeaderText = "销售日期";
                gv_List.Columns[5].Hidden = true;
                gv_List.Columns[6].Hidden = true;
            }
            this.gv_List.DataSource = dtList;
            this.gv_List.DataBind();
            this.gv_List.RecordCount = iRecordCount;
            
        }
        #endregion
        #region Property
        BillListOp Manager = new BillListOp();
        #endregion
    }
}
